package com.cabal.common.util;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLContexts;
import org.apache.http.impl.client.HttpClients;

import javax.net.ssl.SSLContext;

public final class TmsHttpClientManager {

	public static HttpClient getSSLInstance() {
		HttpClient httpClient = null;
		// 创建SSLContext对象，并使用我们指定的信任管理器初始化
		SSLContext sslContext = SSLContexts.createSystemDefault();
		// 从上述SSLContext对象中得到SSLSocketFactory对象
		SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
		httpClient = HttpClients.custom().setSSLSocketFactory(scsf).build();
		return httpClient;
	}

	public static HttpPost getPostMethod(String url) {
		HttpPost post = new HttpPost(url);
		// 设置响应头信息
		post.addHeader("Connection", "keep-alive");
		post.addHeader("Accept", "*/*");
		post.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		post.addHeader("Host", "mp.weixin.qq.com");
		post.addHeader("X-Requested-With", "XMLHttpRequest");
		post.addHeader("Cache-Control", "max-age=0");
		return post;
	}

	public static HttpGet getGetMethod(String url) {
		HttpGet get = new HttpGet(url);
		// 设置响应头信息
		get.addHeader("Connection", "keep-alive");
		get.addHeader("Cache-Control", "max-age=0");
		get.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/;q=0.8");
		return get;
	}
}
